<template>
  <div class="sub-sort">
    <div class="sort">
      <a
        href="javascript:;"
        :class="{ active: activeType === null }"
        @click="activeType = null"
        >默认排序</a
      >
      <a
        href="javascript:;"
        :class="{ active: activeType === 'publishTime' }"
        @click="activeType = 'publishTime'"
        >最新商品</a
      >
      <a
        href="javascript:;"
        :class="{ active: activeType === 'orderNum' }"
        @click="activeType = 'orderNum'"
        >最高人气</a
      >
      <a
        href="javascript:;"
        :class="{ active: activeType === 'evaluateNum' }"
        @click="activeType = 'evaluateNum'"
        >评论最多</a
      >
    </div>
  </div>
</template>
<script>
/**
 * tab类交互
 *  核心点:
 *    1.维护一个index,表示当前激活了哪项, 每次点击tab都会给index重新赋值(当前点击项对应的下标)
 *    2.设计一个active类名 存在表示激活 不存在未激活哦（:class="{active:index === i}"）
 */
import { ref } from 'vue'
export default {
  name: 'SubSort',
  setup () {
    // 1.声明一个标识当前激活的标识(curIndex)
    const activeType = ref(null)
    // 2.点击tab把当前tab对应的字段名称赋值activeType
    return {
      activeType
    }
  }
}
</script>
<style scoped lang='less'>
.sub-sort {
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .sort {
    display: flex;
    a {
      height: 30px;
      line-height: 28px;
      border: 1px solid #e4e4e4;
      padding: 0 20px;
      margin-right: 20px;
      color: #999;
      border-radius: 2px;
      position: relative;
      transition: all 0.3s;
      &.active {
        background: @xtxColor;
        border-color: @xtxColor;
        color: #fff;
      }
      .arrow {
        position: absolute;
        border: 5px solid transparent;
        right: 8px;
        &.up {
          top: 3px;
          border-bottom-color: #bbb;
          &.active {
            border-bottom-color: @xtxColor;
          }
        }
        &.down {
          top: 15px;
          border-top-color: #bbb;
          &.active {
            border-top-color: @xtxColor;
          }
        }
      }
    }
  }
  .check {
    .xtx-checkbox {
      margin-left: 20px;
      color: #999;
    }
  }
}
</style>
